package com.lei.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @author Lei Chu
 * @Date 2020/10/17 16:09
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Staff implements Serializable {

  private Integer id;
  private Integer staffId;
  private String staffName;
  private String password;
  private String phone;
  private String idCard;
  private String address;
  private String createdTime;
  private String resignedTime;
  private Integer status;
  private Integer roleId;
  private String rname;
  private Integer deptid;
  private String dname;
  private String url;
  private Integer age;
  private Integer page;
  private Integer limit;


  public void setPassword() {
    this.password = "123123";
  }

  public void setAge() {
    //获取当前时间的年月日---->Calendar:日历类
    Calendar cal = Calendar.getInstance();
    int yearNow = cal.get(Calendar.YEAR);
    int monthNow = cal.get(Calendar.MONTH)+1;
    int dayNow = cal.get(Calendar.DATE);

    //根据此员工的身份证号获取年月日
    int year = Integer.parseInt(this.idCard.substring(6, 10));
    int month = Integer.parseInt(this.idCard.substring(10,12));
    int day = Integer.parseInt(this.idCard.substring(12,14));

    if ((month < monthNow) || (month == monthNow && day<= dayNow) ){
      this.age = yearNow - year;
    }else {
      this.age = yearNow - year-1;
    }

  }

  public void setCreatedTime() {
    SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date(System.currentTimeMillis());
    this.createdTime = formatter.format(date);

  }

}
